package com.job.sun;

import sun.awt.ScrollPaneWheelScroller;

import java.awt.font.NumericShaper;
import java.util.Scanner;

/**
 * @author legion
 * @version 1.0
 * @since 2022-07-04 15:14:06
 */
public class ThreeGame {
    //到三淘汰,求最后一个人的初始位置
    //剩三个人时中间人为胜利者
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入游戏人数");
        int anInt = sc.nextInt();
        int game = ThreeGame.game(anInt);
        System.out.println(game + "是胜利者");
    }

    public static int game(int a) {
        int[] nums = new int[a];
        //给数组中每一个人赋值
        for (int i = 0; i < nums.length; i++) {
            nums[i] = i + 1;
        }
        for (int i = nums.length; i > 3; i--) {
            int[] newnums = new int[nums.length - 1];
            for (int j = 3; j < i; j++) {
                newnums[j - 3] = nums[j];
            }
            newnums[newnums.length-2]=nums[0];
            newnums[newnums.length-1]=nums[1];
            nums=newnums;
        }

return nums[1];
    }
}